﻿namespace FlowControl
{
    class FlowContainerLine : FlowContainerBase
    {
        protected int currIndex;

        public override void Activate()
        {
            base.Activate();
            if (NumChildren <= 0)
            {
                IsComplete = true;
                return;
            }
            currIndex = 0;
            childs[currIndex].Activate();
        }

        public override void FlowUpdate(float duringTime)
        {
            if (IsComplete) { return; }
            base.FlowUpdate(duringTime);

            IFlowBase currFlow = childs[currIndex];
            if (currFlow.IsComplete)
            {
                currIndex++;
                if (currIndex == NumChildren)
                {
                    IsComplete = true;
                }
                else
                {
                    childs[currIndex].Activate();
                }
            }
            else
            {
                currFlow.FlowUpdate(duringTime);
            }
        }
    }
}